package ChainOfResponsinility;

import java.util.ArrayList;

public class ChainExt implements ChainList{
    public ArrayList<ChainList> chainLists = new ArrayList<>();
    private int flg = 0;


    public ChainExt add(ChainList filter){
        chainLists.add(filter);
        return this;
    }

    public ChainList getChain(){
        if(flg + 1 > chainLists.size()){
            return (m, chain) -> {
                return false;
            };
        }else{
            return chainLists.get(flg++);
        }
    }

    @Override
    public boolean doFilter(Msg msg, ChainList chainList) {
//        for(ChainList list: chainLists){
//            if(!list.doFilter(msg, chainList)){
//                break;
//            }
//        }

        chainList.getChain().doFilter(msg,chainList);

        return true;
    }
}
